﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HFController;

namespace HFWebManage.Source
{
    /// <summary>
    /// 集成HFController.BagePages，可以使用通用的方法
    /// </summary>
    public partial class SourceClass : HFController.BagePages
    {
        /// <summary>
        /// 列表
        /// </summary>
        public List<hf.Model.SourceClass> list = new List<hf.Model.SourceClass>();
        protected void Page_Load(object sender, EventArgs e)
        {
            //判断管理员是否登录
            this.checkAdminIsLogin();

            //是否是第一次加载
            if (!Page.IsPostBack)
            {
                string PageStr = "";
                list = SourceController.getController().getSourceClassList(out PageStr);
                pager.Text = PageStr;

                //获取Action参数，判断是修改还是删除
                string Action = this.GetQuery("action");

                switch (Action)
                {
                    case "modify":
                        //表示修改
                        this.bindmodel();
                        break;
                    case "delete":
                        //表示删除
                        int ID = int.Parse(this.GetQuery("ID"));
                        SourceController.getController().doDelegeSourceClass(ID);
                        break;
                }
            }
        }

        /// <summary>
        /// 绑定需要修改的数据
        /// (就是点击修改某条记录，把上面的修改文本的信息，设置成你点的这条记录)
        /// </summary>
        private void bindmodel()
        {
            int ID = int.Parse(this.GetQuery("ID"));
            //得到这条记录
            hf.Model.SourceClass model = SourceController.getController().getSourceClassModel(ID);
            //输入框赋值
            lblClassName.Text = model.ClassName;
            //隐藏域ID赋值
            IDS.Value = model.ID.ToString();
             
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //获取Action参数，判断是修改还是保存
            string Action = this.GetQuery("action");
            if (Action == "modify")
            {
                //修改记录，刚才bindmodel()方法里，赋值的那两个
                SourceController.getController().doModifySourceClass(int.Parse(IDS.Value), lblClassName.Text);
            }
            else
            {
                SourceController.getController().doAddSourceClass(lblClassName.Text);
            }
        }
    }
}